package com.wit.action;

import java.util.List;

import com.wit.po.Mark;
import com.wit.po.Mdescription;
import com.wit.service.MarkService;
import com.wit.service.MdescriptionService;

public class MdescriptionAction {

	private Mdescription mdescription;
	
	private String markId;
	
	private MdescriptionService mdescriptionService;
	
	private MarkService markService;
	
	private String msg;
	
	private List<Mdescription> mdescriptionList;
	
	public List<Mdescription> getMdescriptionList() {
		return mdescriptionList;
	}

	public void setMdesctiptionList(List<Mdescription> mdescriptionList) {
		this.mdescriptionList = mdescriptionList;
	}

	public String getMsg(){
		return msg;
	}
	
	public MarkService getMarkService() {
		return markService;
	}

	public void setMarkService(MarkService markService) {
		this.markService = markService;
	}

	public String getMarkId() {
		return markId;
	}

	public void setMarkId(String markId) {
		this.markId = markId;
	}

	public Mdescription getMdescription() {
		return mdescription;
	}

	public void setMdescription(Mdescription mdescription) {
		this.mdescription = mdescription;
	}

	public MdescriptionService getMdescriptionService() {
		return mdescriptionService;
	}

	public void setMdescriptionService(MdescriptionService mdescriptionService) {
		this.mdescriptionService = mdescriptionService;
	}
	
	public String addMdescription(){
		System.out.println("in find mdesc by mark..."+markId+"..."+mdescription.getMdescription());
		Mark mark = markService.findByIndentifier(markId);
		mdescription.setMark(mark);
		if(mdescriptionService.addMdescription(mdescription))
			msg = "add successfully";
		return "addPage";
	}
	
	public String modifyMdescription(){
		System.out.println("in modify mdesc ..."+mdescription.getMdescription());
		Mdescription m = mdescriptionService.findByIndentifier(mdescription.getMdid());
		m.setMdescription(mdescription.getMdescription());
		if(mdescriptionService.modifyMdescription(m))
			msg = "add successfully";
		return "editPage";
	}
	
	public String deleteMdescription(){
		System.out.println("in delete mdesc..."+mdescription.getMdid());
		mdescription = mdescriptionService.findByIndentifier(mdescription.getMdid());
		if(mdescriptionService.deleteMdescription(mdescription))
			msg = "add successfully";
		return "listPage";
	}
	
	public String findMdescription(){
		System.out.println("in find mdesc by id..."+mdescription.getMdid());
		mdescription = mdescriptionService.findByIndentifier(mdescription.getMdid());
		return "editPage";
	}
	
	public String findMdescriptionByMark(){
		System.out.println("in find mdesc by mark..."+markId);
		Mark mark = markService.findByIndentifier(markId);
		if(mark != null){
			mdescriptionList = mdescriptionService.findMdescriptionByMark(mark);
		}
		return "listPage";
	}
}
